# -*-coding = utf-8 -*-

# @Time: 2021/4/20 0:21
# @Author: bistro
# @File: p28.py
# @Software: PyCharm
# 28.实现 strStr()
import string


class Solution:
    # def strStr(self, haystack: str, needle: str) -> int:
    #     if needle == "":
    #         return 0
    #     return haystack.find(needle)

    # def strStr(self, haystack: str, needle: str) -> int:
    #     if needle == "":
    #         return 0
    #     n = len(haystack)
    #     m = len(needle)
    #     if needle in haystack:
    #         for i in range(n):
    #             if haystack[i] == needle[0] and haystack[i:i+m] == needle:
    #                 return i
    #     else:
    #         return -1

    def strStr(self, haystack: str, needle: str) -> int:
        if needle == "":
            return 0
        try:
            if haystack.index(needle) >= 0:
                return haystack.index(needle)
        except ValueError as e:
            return -1


s = Solution()
print(s.strStr("xxxx", "xxxx"))
